const $ = document.querySelector.bind(document);
const $$ = document.createElement.bind(document);

const data = [
    {
        code: "G202021819",
        gname: "A供应商",
        sname: "公牛",
        othername: "",
        sort: "",
        unit: "斤",
        single: 147,
        nums: 123,
        innums: 147,
        buyweight: 145,
        buyprice: 2400,
        status: "已预订",
        create_time: "2023-12-12 15:20"
    },
    {
        code: "",
        gname: "",
        sname: "公牛",
        othername: "",
        sort: "",
        unit: "斤",
        single: 147,
        nums: 123,
        innums: 147,
        buyweight: 145,
        buyprice: 2400,
        status: "",
        create_time: ""
    },
    {
        code: "",
        gname: "",
        sname: "公牛",
        othername: "",
        sort: "",
        unit: "斤",
        single: 147,
        nums: 123,
        innums: 147,
        buyweight: 145,
        buyprice: 2400,
        status: "",
        create_time: ""
    }
]
function createTableData() {
    var frag = document.createDocumentFragment();
    let singleCount = 0;
    let numsCount = 0;
    let innumsCount = 0;
    let buyweightCount = 0;
    let priceCount = 0;
    for (let i = 0; i < data.length; i++) {
        var tr = $$("tr");
        singleCount += data[i].single;
        numsCount += data[i].nums;
        innumsCount += data[i].innums;
        buyweightCount += data[i].buyweight;
        priceCount += data[i].buyprice;
        for (key in data[i]) {
            var td = $$("td")
            td.innerText = data[i][key];
            tr.appendChild(td);
        }
        frag.appendChild(tr);
    }
    var tr = $$("tr");
    tr.innerHTML = `
    <td>小计</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>${singleCount}</td>
    <td>${numsCount}</td>
    <td>${innumsCount}</td>
    <td>${buyweightCount}</td>
    <td>${priceCount}</td>
    <td></td>
    <td></td>
`
    frag.append(tr)

    var tr = $$("tr");
    tr.innerHTML = `
    <td>总计</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>${singleCount}</td>
    <td>${numsCount}</td>
    <td>${innumsCount}</td>
    <td>${buyweightCount}</td>
    <td>${priceCount}</td>
    <td></td>
    <td></td>
`
    frag.append(tr)
    $(".table").appendChild(frag);
}
function reset() {
    $("#code").value = "";
    $("#cname").value = "";
    $("#gname").value = "";
    $("#oname").value = "";
    $("#price").value = "";
    $("#status").value = "";
    console.log($(".table").children)
    $(".table").deleteRow(1);
    $(".table").deleteRow(1);
    $(".table").deleteRow(1);
    $(".table").deleteRow(1);
    $(".table").deleteRow(1);
}